package lacus.wd_cinema.component;

import lacus.wd_cinema.entity.Hall;
import lacus.wd_cinema.repository.HallRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.stream.Stream;

@Slf4j
@Component
public class HallInitializer implements CommandLineRunner {
    private final HallRepository hallRepository;

    public HallInitializer(HallRepository hallRepository) {
        this.hallRepository = hallRepository;
    }

    public void run(String... args) {
        Stream.of( // 在系统中添加放映厅
                new Hall("GLD", "黄金厅", 10, 8),
                new Hall("SLV", "白银厅", 12, 10),
                new Hall("JAD", "翡翠厅", 8, 7),
                new Hall("DIA", "钻石厅", 8, 7),
                new Hall("JWL", "宝石厅", 9, 8)
        ).filter(hall ->
                        !hallRepository.existsById(hall.getId()))
                .forEach(hall -> {
                    hallRepository.save(hall);
                    log.info("已添加放映厅: {}", hall);
                });
    }
}
